package cn.yunhe.news.dao.impl;

import cn.yunhe.news.BaseDB;
import cn.yunhe.news.dao.IAdminDao;
import cn.yunhe.news.entity.Admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDao extends BaseDB implements IAdminDao {
    Connection conn = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;

    @Override
    public Admin getAdmin(String name, String pass) {
        Admin admin = null;
        try{
            conn = getConn();
            String sql = "select * from tb_admin where c_name=? and c_pass=?";
            psmt=conn.prepareStatement(sql);
            psmt.setObject(1,name);
            psmt.setObject(2,pass);
            rs=psmt.executeQuery();
            if (rs.next()){
                admin=new Admin(rs.getInt("c_id"),rs.getString("c_name"),rs.getString("c_pass"),rs.getInt("c_flag"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return admin;
    }
}
